package com.jigsaw.util;

import com.jigsaw.model.MoviesCateEntity;
import com.jigsaw.model.MoviesInfoEntity;
import com.jigsaw.model.UserEntity;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.data.domain.Page;

import java.util.List;
import java.util.Set;

/**
 * Created by Jigsaw on 2016/4/13.
 */
public class JsonHelper {
    public static String MoviestoJson(JSONObject moviesJson, MoviesInfoEntity movies) throws JSONException {
        moviesJson.put("mid", movies.getMid());
        moviesJson.put("title", movies.getTitle());
        MoviesCateEntity cate = movies.getCateById();
        moviesJson.put("category", cate.getCategory());
        moviesJson.put("rating", movies.getRating());
        moviesJson.put("image", movies.getImage());
        moviesJson.put("director", movies.getDirector());
        moviesJson.put("actors", movies.getActors());
        moviesJson.put("long_time", movies.getLongTime());
        moviesJson.put("des", movies.getDes());
        moviesJson.put("read_time", movies.getReadTime());
        return moviesJson.toString();
    }

    public static String MoviesToList(List<String> temp, Set<MoviesInfoEntity> m) {
        for (MoviesInfoEntity movies : m) {
            JSONObject moviesJson = new JSONObject();
            try {
                temp.add(JsonHelper.MoviestoJson(moviesJson, movies));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return temp.toString();

    }

    public static String MoviesToList(List<String> temp, Page<MoviesInfoEntity> m) {
        for (MoviesInfoEntity movies : m) {
            JSONObject moviesJson = new JSONObject();
            try {
                temp.add(JsonHelper.MoviestoJson(moviesJson, movies));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return temp.toString();

    }
    public static String MoviesToList(List<String> temp, List<MoviesInfoEntity> m) {
        for (MoviesInfoEntity movies : m) {
            JSONObject moviesJson = new JSONObject();
            try {
                temp.add(JsonHelper.MoviestoJson(moviesJson, movies));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return temp.toString();

    }
}
